package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.mapper.DtsPermissionMapper;
import com.qf.pojo.DtsPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author jiangjingbo
 * @version V1.0
 * @Project java2203
 * @Package com.qf.service
 * @Description:
 * @Date 2022/6/16 17:36
 */
@Service
public class PermissionServiceimpl implements PermissionService {

    @Autowired
    private DtsPermissionMapper permissionMapper;
    /**
     * 根据角色id查询 用户权限
     * @param ids
     * @return
     */
    @Override
    public Set<String> queryPermissonByRoleIds(Integer[] ids) {
        //判断ids如果为空, 返回空的set集合
        if (ids == null || ids.length ==0) {
            return  new HashSet<String>();
        }
        QueryWrapper<DtsPermission> queryWrapper= new QueryWrapper();
        queryWrapper.in("role_id",ids);
        queryWrapper.eq("deleted",false);

        List<DtsPermission> list = permissionMapper.selectList(queryWrapper);
        Set<String> set = new HashSet<>();
        for (DtsPermission permission : list) {
            set.add(permission.getPermission());
        }
        return set;
    }
}
